package neko.net;
import neko.net.InternalSocket;
import neko.io.Error;
import neko.net.Socket;

class InternalSocketOutput
	extends neko.io.Output,
	implements neko.net.SocketOutput
{
	private var __socket 	: InternalSocket;
	var __s 				: SocketHandle; // not used.

	public function new(s) {
		__socket = s;
	}

	public override function writeChar( c : Int ) {
		try {
			__socket.write(Std.chr(c));
		} catch( e : Dynamic ) {
			throw Custom(e);
		}
	}

	public override function writeBytes( buf : String, pos : Int, len : Int) : Int {
		try {
			__socket.write(buf.substr(pos,len));
		} catch( e : Dynamic ) {
			throw Custom(e);
		}
		return len;
	}

	public override function close() {
		super.close();
		if( __socket != null ) __socket.close();
	}
}
